/////////////////////////////////////////////////////////
/*******************************************************
        Sample of Wii cursor with sound by AcADIeN
       with the help of every homebrew apps arround
*******************************************************/
////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <ogcsys.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <fat.h>
#include "../../song_lib/snd.h"       // sound library
#include "../../song_lib/song_lib.h"       // sound library
#include "oggplayer.h"
#include "mario.h"
#include "explosion.h"
#include "gfx/pointer.h"
#include "gfx/board.h"
#include "gfx/boat.h"
#include "gfx/miss.h"
#include "gfx/over.h"
#include "gfx/fire.h"
#include "gcmodplay.h"
#include "GRRLIB/GRRLIB.h"

Mtx GXmodelView2D;

int main(int argc, char **argv) {
	u8 *texPointer = GRRLIB_LoadTexture(generic_point);
	u8 *texBoard = GRRLIB_LoadTexture(board);
	u8 *texBoat = GRRLIB_LoadTexture(boat);
	u8 *texFire = GRRLIB_LoadTexture(fire);
	u8 *texMiss = GRRLIB_LoadTexture(miss);
	u8 *texOver = GRRLIB_LoadTexture(over);
	VIDEO_Init();
	GRRLIB_InitVideo();
	WPADData *wPad;
	WPAD_Init();
	WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
	WPAD_SetVRes(0, 640, 480);
	fatInit(8, false);
	SND_Init(INIT_RATE_48000); // Initialize the Sound Lib
	SND_Pause(0); // the sound loop is running now
	PlayOgg(mem_open(mario, mario_size),0,OGG_INFINITE_TIME);
	while(1) 
	{
		WPAD_ScanPads();
	        u32 wpaddown = WPAD_ButtonsDown(0);
		GRRLIB_FillScreen(0xFFFFFFFF);
		wPad = WPAD_Data(0);/*
		if (wPad->ir.x > 242 && wPad->ir.x < 398 && wPad->ir.y > 220 && wPad->ir.y < 260) {
			if (wpaddown & WPAD_BUTTON_A) {
				//PlayOgg(mem_open(explosion, explosion_size),0,OGG_ONE_TIME);
			}
		}*/
		GRRLIB_DrawImg(0,0,640,480,texBoard,0,1,1,255);
		GRRLIB_DrawImg(43,43,24,24,texBoat,0,1,1,255);
		if (wPad->ir.valid) {
			GRRLIB_DrawImg(wPad->ir.x-(96/2), wPad->ir.y-(96/2), 96, 96, texPointer, wPad->ir.angle, 1, 1, 255 );
			if (wPad->ir.x > 355 && wPad->ir.x < 379) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(353,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(353,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(353,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(353,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(353,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(353,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(353,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(353,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(353,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(353,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 382 && wPad->ir.x < 406) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(380,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(380,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(380,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(380,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(380,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(380,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(380,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(380,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(380,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(380,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 409 && wPad->ir.x < 433) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(407,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(407,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(407,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(407,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(407,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(407,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(407,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(407,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(407,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(407,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 436 && wPad->ir.x < 460) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(434,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(434,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(434,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(434,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(434,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(434,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(434,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(434,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(434,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(434,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 463 && wPad->ir.x < 487) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(461,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(461,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(461,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(461,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(461,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(461,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(461,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(461,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(461,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(461,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 490 && wPad->ir.x < 514) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(488,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(488,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(488,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(488,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(488,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(488,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(488,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(488,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(488,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(488,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 517 && wPad->ir.x < 541) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(515,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(515,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(515,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(515,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(515,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(515,176,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(515,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(515,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(515,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(515,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 544 && wPad->ir.x < 568) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(542,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(542,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(542,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(542,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(542,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(542,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(542,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(542,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(542,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(542,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 571 && wPad->ir.x < 595) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(569,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(569,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(569,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(569,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(569,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(569,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(569,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(569,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(569,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(569,281,28,28,texOver,0,1,1,255);
				}
			}
			if (wPad->ir.x > 598 && wPad->ir.x < 622) {
				if (wPad->ir.y > 43 && wPad->ir.y < 67) {
					GRRLIB_DrawImg(596,41,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 70 && wPad->ir.y < 94) {
					GRRLIB_DrawImg(596,68,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 96 && wPad->ir.y < 120) {
					GRRLIB_DrawImg(596,94,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 123 && wPad->ir.y < 147) {
					GRRLIB_DrawImg(596,121,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 150 && wPad->ir.y < 174) {
					GRRLIB_DrawImg(596,148,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 176 && wPad->ir.y < 200) {
					GRRLIB_DrawImg(596,174,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 203 && wPad->ir.y < 227) {
					GRRLIB_DrawImg(596,201,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 229 && wPad->ir.y < 253) {
					GRRLIB_DrawImg(596,227,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 256 && wPad->ir.y < 280) {
					GRRLIB_DrawImg(596,254,28,28,texOver,0,1,1,255);
				}
				if (wPad->ir.y > 283 && wPad->ir.y < 307) {
					GRRLIB_DrawImg(596,281,28,28,texOver,0,1,1,255);
				}
			}
			
		}
		GRRLIB_Render();	
		if (wpaddown & WPAD_BUTTON_HOME) {
			exit(0);
		}
	}
	StopOgg();
	WPAD_Shutdown();
	SND_End();
	return 0;
}



